<template>
  <div class="column-detail-page w-75 mx-auto">
    <div class="column-info row mb-4 border-bottom pb-4 align-items-center" v-if="column">
      <div class="col-3 text-center">
        <img :src="column.avatar" :alt="column.title" class="rounded-circle border w-100">
      </div>
      <div class="col-9">
        <h4>{{column.title}}</h4>
        <p class="text-muted">{{column.description}}</p>
      </div>
    </div>
    <post-list :currentId="currentId" :list="list"></post-list>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted,computed,PropType } from 'vue'
import { useRoute } from 'vue-router'

import {useStore} from 'vuex'
import {GlobalDataProps,PostProps} from '@/store/index'
import PostList from '@/components/PostList/PostList.vue'

export default defineComponent({
  components: {
    PostList
  },
  setup() {
    const route = useRoute()
    const currentId = route.query.id
    onMounted(() => {
     console.log('onMounted...');
     console.log('路由Id:',currentId); 
    })

    

    const store = useStore<GlobalDataProps>()
    // const column = computed(()=> store.state.columns.find(c => String(c.id) == currentId))

    // const list = computed(()=> store.state.posts.filter(item => {
    //   return String(item.columnId) == currentId
    // }))

    // 采用 store 的getters方式
    const column  = store.getters.getColumnById(currentId)
    const list  = store.getters.getPostListById(currentId)

    return {
      column,
      list,
      currentId: Number(currentId)
    }
  }
})
</script>
